<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>函数形参与实参</title>
</head>

<body>
  <script>
    // 剩余形参与可变长度实参列表
    function max(first = -Infinity, ...args) {
      console.log(first);
      //arguments是类数组对象
      console.log(arguments);
      console.log(args)
      console.log(...args);
    }


    max(1, 2, 3, 4, 5)

    // 在函数调用中使用扩展操作符
    // function timed(f) {
    //   return function (...args) {
    //     console.log(args);
    //     console.log(f);
    //     // console.log(`${f.name}`);
    //     let startTime = Date.now();
    //     console.log(startTime);
    //     try {
    //       console.log(...args);
    //       return f(...args)
    //     }
    //     finally {
    //       console.log(`${f.name},${Date.now() - startTime}ms`);
    //     }
    //   }
    // }

    // function benchmark(n) {
    //   let sum = 0;
    //   for (let i = 1; i <= n; i++) sum += i;
    //   return sum
    // }
    // // console.log(benchmark(100));
    // console.log(timed(benchmark)(5));
    // console.log(timed(5));




    // 把函数实参解构为形参
    // function arraycopy({ from, to = from, n = from.length, fromIndex = 0, toIndex = 0 }) {
    //   console.log(from);
    //   let valuesToCopy=from.slice(fromIndex,fromIndex+n)
    //   console.log(to);
    //   console.log(n);
    //   console.log(fromIndex);
    //   console.log(toIndex);
    // }
    // let a = [1, 2, 3, 4, 5], b = [9, 8, 7, 6, 5]
    // arraycopy({ from: a, n: 3, to: b, toIndex: 4 })


    function sum(a){
      for(let element of a){
        console.log(typeof element);
      }
    }
    sum([1,2,'3'])
  </script>
</body>

</html>